import { defineComponent, ref, shallowRef, openBlock, createElementBlock, createVNode, unref, mergeProps, withCtx, Fragment, renderList, createBlock, toHandlers, renderSlot, resolveDynamicComponent } from "vue";
import { Input, InputSearch, Select, Checkbox, CheckboxGroup, Cascader, DatePicker, RangePicker, TimePicker, InputNumber, Textarea, Radio, RadioGroup, Switch, Upload, TreeSelect, TimeRangePicker, Button, InputPassword, Form, Row, Col, FormItem } from "ant-design-vue";
const _hoisted_1 = { class: "me-dynamic-form" };
const _sfc_main = /* @__PURE__ */ defineComponent({
  ...{
    name: "me-dynamic-form"
  },
  __name: "dynamic-form",
  props: {
    formProps: { default() {
      return {};
    } },
    dataSource: { default() {
      return [];
    } }
  },
  setup(__props, { expose: __expose }) {
    const props = __props;
    const componentMapper = ref({
      Input: shallowRef(Input),
      InputSearch: shallowRef(InputSearch),
      Select: shallowRef(Select),
      Checkbox: shallowRef(Checkbox),
      CheckboxGroup: shallowRef(CheckboxGroup),
      Cascader: shallowRef(Cascader),
      DatePicker: shallowRef(DatePicker),
      RangePicker: shallowRef(RangePicker),
      TimePicker: shallowRef(TimePicker),
      InputNumber: shallowRef(InputNumber),
      Textarea: shallowRef(Textarea),
      Radio: shallowRef(Radio),
      RadioGroup: shallowRef(RadioGroup),
      Switch: shallowRef(Switch),
      Upload: shallowRef(Upload),
      TreeSelect: shallowRef(TreeSelect),
      TimeRangePicker: shallowRef(TimeRangePicker),
      Button: shallowRef(Button),
      Custom: shallowRef(null),
      InputPassword: shallowRef(InputPassword)
    });
    const formRef = ref();
    __expose({
      instance: formRef
    });
    return (_ctx, _cache) => {
      return openBlock(), createElementBlock("div", _hoisted_1, [
        createVNode(unref(Form), mergeProps({
          ref_key: "formRef",
          ref: formRef
        }, _ctx.formProps), {
          default: withCtx(() => [
            (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.dataSource, (item) => {
              return openBlock(), createElementBlock(Fragment, null, [
                item instanceof Array ? (openBlock(), createBlock(unref(Row), {
                  key: 0,
                  gutter: [16, 16]
                }, {
                  default: withCtx(() => [
                    (openBlock(true), createElementBlock(Fragment, null, renderList(item, (a, index) => {
                      return openBlock(), createBlock(unref(Col), {
                        key: index,
                        span: a.span || Math.floor(24 / item.length)
                      }, {
                        default: withCtx(() => [
                          createVNode(unref(FormItem), mergeProps(toHandlers(a.formItemListeners || {}), { ref_for: true }, a.formItemProps), {
                            default: withCtx(() => [
                              a.component === "Custom" ? renderSlot(_ctx.$slots, a.slot, {
                                key: 0,
                                item: a
                              }) : (openBlock(), createBlock(resolveDynamicComponent(componentMapper.value[a.component]), mergeProps({ key: 1 }, toHandlers(a.formItemControlListeners || {}), {
                                [a.modelType]: _ctx.formProps.model[a.formItemProps.name],
                                ["onUpdate:" + a.modelType]: ($event) => _ctx.formProps.model[a.formItemProps.name] = $event,
                                ref_for: true
                              }, a.formItemControlProps), null, 16))
                            ]),
                            _: 2
                          }, 1040)
                        ]),
                        _: 2
                      }, 1032, ["span"]);
                    }), 128))
                  ]),
                  _: 2
                }, 1024)) : (openBlock(), createBlock(unref(FormItem), mergeProps({ key: 1 }, toHandlers(item.formItemListeners || {}), { ref_for: true }, item.formItemProps), {
                  default: withCtx(() => [
                    item.component === "Custom" ? renderSlot(_ctx.$slots, item.slot, {
                      key: 0,
                      item
                    }) : (openBlock(), createBlock(resolveDynamicComponent(componentMapper.value[item.component]), mergeProps({ key: 1 }, toHandlers(item.formItemControlListeners || {}), {
                      [item.modelType]: _ctx.formProps.model[item.formItemProps.name],
                      ["onUpdate:" + item.modelType]: ($event) => _ctx.formProps.model[item.formItemProps.name] = $event,
                      ref_for: true
                    }, item.formItemControlProps), null, 16))
                  ]),
                  _: 2
                }, 1040))
              ], 64);
            }), 256)),
            renderSlot(_ctx.$slots, "default")
          ]),
          _: 3
        }, 16)
      ]);
    };
  }
});
export {
  _sfc_main as default
};
//# sourceMappingURL=dynamic-form.vue2.mjs.map
